<template>
    <div>
        <h2 style="text-align: center;">我的挂号记录</h2>
        <br>
        <el-table
                :data="list.slice((currentPage-1)*pagesize,currentPage*pagesize)"

        >
            <el-table-column
                    label="日期"
                    prop="date"
                    align="center"
            >
            </el-table-column>
            <el-table-column
                    label="科室"
                    align="center">
                <template #default="scope">
                    <p  v-for="depart in secondList" >
                        <span v-if="scope.row.departmentId==depart.id">{{depart.name}}</span>
                    </p>
                </template>
            </el-table-column>
            <el-table-column
                    label="挂号医生"
                    prop="dname"
                    align="center">
            </el-table-column>
            <el-table-column
                    label="类别"
                    align="center" >
                <template #default="scope">
                    <p v-if="scope.row.level=='1'">专家号</p>
                    <p v-if="scope.row.level=='2'">普通号</p>
                </template>
            </el-table-column>
            <el-table-column
                    label="挂号费"
                    align="center" >
                <template #default="scope">
                    <p v-if="scope.row.level=='1'">30元</p>
                    <p v-if="scope.row.level=='2'">15元</p>
                </template>
            </el-table-column>
            <el-table-column
                    label="诊治状态"
                    align="center">
                <template #default="scope">
                    <p v-if="scope.row.flags==0">未诊治</p>
                    <p v-else>已诊治</p>
                </template>
            </el-table-column>

        </el-table>
        <center>
            <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="currentPage"
                    :page-sizes="[5, 10, 20, 40]"
                    :page-size="pagesize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="list.length"
            >
            </el-pagination>
        </center>
    </div>
</template>

<script>
    import axios from "axios";

    export default {
        name: "OrderList",
        data() {
            return {
                id:'',
                doctors:{
                    avatar:'',
                    deleted:0,
                    gmtCreate:'',
                    gmtUpdate:'',
                    id: '',
                    name: '',
                    info:'',
                    career:'',
                    level:'',
                    sex:'',
                    idCard:'',
                    password:'',
                    phone:'',
                    departmentId: '',
                },
                doctors:[],
                list:{
                    id: "",
                    date: "",
                    pid: "",
                    did: "",
                    dname:'',
                    departmentId: '',
                    flags:3,
                    level:0,
                },
                secondList:{
                    id:'',
                    name:'',
                },
                list:[],
                currentPage:1, //初始页
                pagesize:15,    //    每页的数据
                dialogFormVisible: false,
            }
        },
        activated(){
          this.create();
          this.getDepartment();
        },
        methods: {
            create(){
                this.id=localStorage.getItem("id");
                axios.post("http://119.29.60.153:8001/doctorservice/registration/getRegistrationByPId?id="+this.id).then(resp=> {
                    this.doctors=resp.data.data.doctors;
                    this.list= resp.data.data.list;
                    for(var i=0;i<this.list.length;i++){
                        this.list[i].dname=this.doctors[i].name;
                        this.list[i].departmentId=this.doctors[i].departmentId;
                        this.list[i].level=this.doctors[i].level;
                    }
                })
            },
            getDepartment(){
                axios.get("http://119.29.60.153:8001/doctorservice/department/getSecondDepartment").then(resp=> {
                    this.secondList = resp.data.data.secondList;
                })
            },
            handlePay(index, row) {
                console.log(row.name);
                this.$router.push({name:'PayPage',params:{name:row.name}});
            },
            handleSizeChange: function (size) {
                this.pagesize = size;
                console.log(this.pagesize)  //每页下拉显示数据
            },
            handleCurrentChange: function(currentPage){
                this.currentPage = currentPage;
                console.log(this.currentPage)  //点击第几页
            },
        },
    }
</script>

<style scoped>

</style>